<template>
	<view class="sign_in">
		<image class="background" src="@/static/images/sign_background.jpg" mode="widthFix"></image>
		<view class="main">
			<view class="title">注册</view>
			<view class="input">
				<u-input v-model="username" type="text" placeholder='请输入姓名' />
			</view>
			<view class="input">
				<u-input v-model="phone" type="number" placeholder='请输入手机号' />
			</view>
			<!-- <view class="input_pass">
				<view class="pass">
					<u-input v-model="code" type="number" :clearable='false' placeholder='请输入验证码' />
				</view>
				<text class="btn" @click="sendCodeBtn">{{codeTxt}}</text>
			</view> -->
			<view class="input">
				<u-input v-model="pass" maxlength='16' type="password" placeholder='请输入8-16位数字、英文组合密码' />
			</view>
			<view class="input">
				<u-input v-model="pass_two" maxlength='16' type="password" placeholder='请再次输入8-16位数字、英文组合密码' />
			</view>
			<view class="input">
				<u-input v-model="invitation_code" type="text" placeholder='请输入邀请码' />
			</view>
			<view class="change_txt">
				<image v-if="changeIndex" @click="changeBtn" src="@/static/images/change_icon2.png" mode=""></image>
				<!-- <image v-else @click="changeBtn" src="@/static/images/change_icon1.png" mode=""></image> -->
				<!-- <text class="tip">我已阅读并同意</text>
				<text class="txt" @click="textBtn(1)">《用户协议》</text>
				<text class="tip">和</text>
				<text class="txt" @click="textBtn(2)">《隐私政策》</text> -->
			</view>
			<view class="in_btn" @click="registerBtn">注册</view>
			<view class="bot_txt" @click="siginBtn">登录</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				code:'',
				pass:'',
				pass_two:'',
				invitation_code:'',
				// 
				changeIndex:false,
				username:'',
				//
				disabled:false,
				codeTxt:'发送验证码',
				sendTime:60,
				time:null,
			};
		},
		onLoad(opt) {
			if(opt.share_code){
				this.invitation_code=opt.share_code
			}
		},
		methods:{
			// 
			textBtn(val){
				uni.navigateTo({
					url:'/pages/other/text?type='+val
				})
			},
			// 发送验证码
			// sendCodeBtn(){
			// 	var that = this
			// 	if(that.disabled){
			// 		return
			// 	}
			// 	if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
			// 		that.$tips.showToast('请输入正确的手机号')
			// 		return
			// 	}else{
			// 		that.$tips.showLoading('发送中')
			// 		var params = {
			// 			mobile:that.phone,
			// 			event:'register'
			// 		}
			// 		that.$httpApi.smsSend(params).then((res)=>{
			// 			that.$tips.hideLoading()
			// 			if(res.code==1){
			// 				if (!that.timer) {
			// 				  that.disabled = true
			// 				  that.codeTxt = that.sendTime+'s'
			// 				  that.timer = setInterval(() => {
			// 				    if (that.sendTime > 0 && that.sendTime <= 60) {
			// 				      that.sendTime--
			// 				      that.codeTxt = that.sendTime+'s'
			// 				    } else {
			// 				      that.disabled = false
			// 				      that.sendTime = 60
			// 				      that.codeTxt = '重新获取'
			// 				      clearInterval(that.timer)
			// 				      that.timer = null;
			// 				    }
			// 				  }, 1000)
			// 				}
			// 			}
			// 		})
			// 	}
			// },
			//协议
			// changeBtn(type){
			// 	this.changeIndex=!this.changeIndex
			// },
			// 注册
			registerBtn(){
				var that = this
				if(that.username == ''){
					that.$tips.showToast('请输入用户名')
					return
				}else if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
					that.$tips.showToast('请输入正确的手机号')
					return
				}else if(that.pass==''){
					that.$tips.showToast('请输入密码')
					return
				}else if(that.pass.length<6){
					that.$tips.showToast('密码格式不正确')
					return
				}else if(that.pass_two==''){
					that.$tips.showToast('请再次输入密码')
					return
				}else if(that.pass!=that.pass_two){
					that.$tips.showToast('密码不一致')
					return
				}else{
					that.$tips.showLoading('加载中')
					var params = {
						mobile:that.phone,
						username:that.username,
						password:that.pass,
						towpassword:that.pass_two,
						invitation_code:that.invitation_code
					}
					that.$httpApi.userRegister(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							that.$store.commit('SET_TOKEN',res.data.userinfo.token)
							that.$store.dispatch('GetUserInfo')
							uni.switchTab({
								url:'/pages/shop/shop'
							})
						}
					})
				}
			},
			// 登录
			siginBtn(){
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="less">
	.sign_in{
		width: 100%;
		height: 100vh;
		.background{
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1;
			display: block;
			width: 100%;
			height: 100%;
		}
		.main{
			position: relative;
			z-index: 2;
			width: 100%;
			padding: 150rpx 65rpx 50rpx;
			.title{
				width: 100%;
				font-size: 64rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: 500;
				color: #26C281;
				padding-bottom: 50rpx;
			}
			.input{
				width: 100%;
				height: 80rpx;
				margin-top: 40rpx;
				border-bottom: 1rpx solid rgba(190, 190, 190, 0.2);
				::v-deep .u-input__input{
					font-size: 32rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}
			}
			.input_pass{
				width: 100%;
				height: 80rpx;
				margin-top: 40rpx;
				border-bottom: 1rpx solid rgba(190, 190, 190, 0.2);
				display: flex;
				align-items: center;
				justify-content: space-between;
				.pass{
					width: calc(100% - 160rpx);
					::v-deep .u-input__input{
						font-size: 32rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
				.btn{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #26C281;
				}
			}
			.change_txt{
				width: 100%;
				margin-top: 30rpx;
				display: flex;
				align-items: center;
				image{
					display: block;
					width: 32rpx;
					height: 32rpx;
					margin-right: 12rpx;
				}
				.tip{
					font-size: 26rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #888888;
				}
				.txt{
					font-size: 26rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #0EBD8D;
				}
			}
			.in_btn{
				margin-top: 100rpx;
				width: 100%;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				background: #26C281;
				border-radius: 44rpx;
			}
			.bot_txt{
				width: 100%;
				margin-top: 100rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #26C281;
			}
		}
	}
</style>
